Skip to content

feat(postgres): Cloudflare Hyperdrive driver — tokio-postgres on wasm32 - #57

Merged
themixednuts merged 1 commit into
mainfrom
feat/hyperdrive-driver
Aug 7, 2026
Merged

feat(postgres): Cloudflare Hyperdrive driver — tokio-postgres on wasm32#57
themixednuts merged 1 commit into
mainfrom
feat/hyperdrive-driver

Conversation

@themixednuts

Copy link
Copy Markdown
Owner

Summary

Runs the existing tokio-postgres driver inside Cloudflare Workers through the Hyperdrive binding — not a separate driver. worker::Socket implements tokio's AsyncRead/AsyncWrite, so Config::connect_raw yields the same Client the native driver wraps; the whole surface (queries, row streaming, transactions, savepoints, prepared statements + cache, relational direct/prepared, migrate incl. dirty detection and --repair, push, introspect) compiles verbatim for wasm32. The only new code is the 42-line dial module postgres::hyperdrive::{connect, connect_raw} (spawn_local for the connection future, NoTls per Hyperdrive's edge-terminated TLS).

  • Workspace tokio-postgres dep drops runtime (it only gates Config::connect); native consumers re-add it additively — native builds byte-identical.
  • Manifest documents the cargo footgun: with a dep and feature sharing the name tokio-postgres, only the weak tokio-postgres?/js form avoids re-enabling runtime.
  • PG binary wire format → exact i64/numeric/bytea, unlike the JS-number-bounded d1/durable drivers.
  • CI: wasm32 checks for hyperdrive and hyperdrive,query added to the wasm-drivers job.

Test plan

  • cargo check --target wasm32-unknown-unknown --no-default-features --features hyperdrive (+ ,query)
  • Full-surface wasm compile proof (every driver API called)
  • Native regression: workspace check/clippy --all-features --all-targets -D warnings, migrations/core/postgres crate suites, root sqlite suite
  • Live PG matrix — runs in this PR's CI (local Docker engine unavailable)

🤖 Generated with Claude Code

Run the existing tokio-postgres driver inside Cloudflare Workers through
the Hyperdrive binding. Not a separate driver: worker::Socket implements
tokio's AsyncRead/AsyncWrite, so Config::connect_raw hands back the same
Client the native driver wraps — the entire query surface, transactions,
savepoints, prepared statements and cache, relational queries, migrate
(incl. dirty detection and repair), push, and introspect compile verbatim
for wasm32-unknown-unknown. The new module is only the dial:
postgres::hyperdrive::{connect, connect_raw}, spawning the connection
future via spawn_local and using NoTls per Hyperdrive's edge-terminated
TLS. PG's binary wire format means exact i64/numeric/bytea round-trips,
unlike the JS-number-bounded d1/durable drivers.

Feature wiring: the workspace tokio-postgres dep drops its runtime
feature (which only gates Config::connect and pulls tokio/net + mio);
native consumers re-add it additively, so native builds are unchanged.
The hyperdrive feature must use the weak form tokio-postgres?/js — the
plain form resolves to the same-named root feature and drags runtime
back in. CI gains wasm32 checks for hyperdrive and hyperdrive,query.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 7, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@themixednuts
themixednuts merged commit e1bd150 into main Aug 7, 2026
35 checks passed
@themixednuts
themixednuts deleted the feat/hyperdrive-driver branch August 7, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant